/*
 * JGarminImgParser - A java library to parse .IMG Garmin map files.
 *
 * Copyright (C) 2006 Patrick Valsecchi
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package mapcontrol.searchmap;

import imgparser.CoordUtils;
import mapcontrol.ImgConstants;
import imgparser.labels.Label;

import java.io.IOException;

public class FoundPoly extends FoundObject
{
    private final int[] longitudes;

    private final int[] latitudes;

    private final boolean line;

    public FoundPoly(int type, int[] longitudes, int[] latitudes, int nbPoints, Label label, boolean line)
    {
        super(type, label);
        this.longitudes=new int[nbPoints];
        this.latitudes=new int[nbPoints];
        System.arraycopy(longitudes, 0, this.longitudes, 0, nbPoints);
        System.arraycopy(latitudes, 0, this.latitudes, 0, nbPoints);
        this.line=line;
    }

    public int[] getLatitudes() {
        return latitudes;
    }

    public int[] getLongitudes() {
        return longitudes;
    }

    
    public int getLongitude()
    {
        return longitudes[longitudes.length/2];
    }

    public int getLatitude()
    {
        return latitudes[latitudes.length/2];
    }

    public boolean isLine() {
        return line;
    }
    
    

    public void toDebugHtml(StringBuilder result) throws IOException
    {
        if(line){
            //TODO PIETER remove points in info
            String points="";
            for(int i=0;i<longitudes.length;i++){
                double longitude = CoordUtils.toWGS84(longitudes[i]);
                double latitude = CoordUtils.toWGS84(latitudes[i]);
                points+= "("+longitude+";"+latitude+") <br>";
            }
            result.append("<b>Polyline:<br> "+points+"</b><br>\n");
        }
        else
            result.append("<b>Polygon</b><br>\n");
        ImgConstants.Description setup=ImgConstants.getPolyType(getType(), line);
        result.append("what=").append(setup.getDescription()).append(" (").append(setup.getPriority()).append(")").append("<br>");
        super.toDebugHtml(result);
    }
}
